﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XCommunity.Views;
using XCommunity.Data;
using XCommunity.Frames;
using System.Xml.Linq;

namespace XCommunity.Forums.Views
{

  /// <summary>
  /// 定义版面框架视图
  /// </summary>
  public class BoardFrameView : PanelFrameView
  {

    public BoardFrameView( ForumsViewService service, XElement configElement, ForumsBoardFrame boardFrame )
      : base( service, configElement )
    {
      Service = service;
      BoardFrame = boardFrame;

    }



    protected new ForumsViewService Service
    {
      get;
      private set;
    }


    public IEnumerable<TopicItemView> TopicItems
    {
      get
      {

        var items = from topic in BoardFrame.GetTopics()
                    orderby topic.GetLastPublishPost().PublishDate descending
                    select Service.GetTopicItemView( topic );

        return Service.GetFilters( this, "TopicItems" ).Filter( items );

      }
    }

    protected virtual IPagingDataSource<TopicItemView> TopicItemsPaging
    {
      get
      {
        return Service.GetPagingFilters( this, "TopicItemPaging" ).Filter( TopicItems.ToPagingSource() );
      }
    }



    public int Topics
    {
      get { return BoardFrame.GetTopicNumber(); }
    }

    public int Posts
    {
      get { return BoardFrame.GetPostNumber(); }
    }





    public ForumsBoardFrame BoardFrame
    {
      get;
      private set;
    }


    public override object BaseObject
    {
      get { return BoardFrame; }
    }

  }
}
